<template>
  <div class="item-card" @click="toDetail(itemId || '123')">
    <el-card shadow="never" :body-style="{ padding: '0px' }">
      <img
        :src="
          thumb ||
          'https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png'
        "
        class="image" style="width: 218px; height: 218px"
      />
      <div class="item-card__desc" style="padding: 14px">
        <span class="title">
          {{ title || '【圣诞礼物】Dior迪奥 漫舞花漾甜心女士淡香水 EDT' }}
        </span>
        <div class="price">
          <span>￥</span>
          <span>{{ price || 200 }}</span>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import { defineComponent } from '@vue/composition-api';
import { useNav } from '../hooks';
import { RouterMap } from '../utils/constants';

export default defineComponent({
  props: {
    itemId: [String, Number],
    title: String,
    price: Number,
    thumb: String,
  },
  setup(props, context) {
    const { to } = useNav(context);

    const toDetail = (id) => {
      to(RouterMap.Detail, { itemId: id });
    };
    return { toDetail };
  },
});
</script>

<style lang="less" scoped>
.item-card {
  width: 220px;
  cursor: pointer;
  &__desc {
    .title {
      display: inline-block;
      white-space: nowrap;
      width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }
    .price {
      color: rgb(255, 48, 48);
      font-size: 0.9rem;
    }
  }
}
</style>
